/*************************************************************************
> File Name: reconfig.c
> Author:
> Mail:
> Created Time: Mon 13 Nov 2017 11:25:58 AM CST
************************************************************************/
#include <string.h>
#include <stdio.h>
#include <ijpege_common.h>
#ifdef DMALLOC
#include <imp/dmalloc.h>
#endif
#define IJPEGE_RCFG_QL_V        (1<<IJPEGE_RCFG_QL_ID)
#define IJPEGE_RCFG_QL_CLR(v) (v = (v&(~(IJPEGE_RCFG_QL_V))))
#define IJPEGE_RCFG_QL_SET(v) (v = (v|(IJPEGE_RCFG_QL_V)))
#define IJPEGE_RCFG_QL_GET(v) (v&(IJPEGE_RCFG_QL_V))

int ijpege_reconfig(ijpege_t *h)
{
    int i = 0;
    ijpege_pthread_mutex_lock(&h->reconfig.mutex_rcfg);
    if (h->reconfig.idr_reconfig_cnt)
    {
        if (IJPEGE_RCFG_QL_GET(h->reconfig.idr_reconfig_cnt))
        {
            h->icodec_io.protocol.jpege.user_ql_en = h->reconfig.user_ql_en;
            for (i = 0; i < 128; i++)
            {
                h->icodec_io.protocol.jpege.qmem_table[i] = qlook[h->reconfig.qmem_table[i]];
            }
            //memcpy(h->icodec_io.protocol.jpege.qmem_table,h->reconfig.qmem_table,sizeof(h->reconfig.qmem_table));
            IJPEGE_RCFG_QL_CLR(h->reconfig.idr_reconfig_cnt);
        }
    }
    ijpege_pthread_mutex_unlock(&h->reconfig.mutex_rcfg);
    return 0;
}

int ijpege_reconfig_ql_set(ijpege_t *h,const void *param)
{
    ijpege_ql_param_t *pstJpegeQl = (ijpege_ql_param_t *)param;
    ijpege_pthread_mutex_lock(&h->reconfig.mutex_rcfg);
    h->reconfig.user_ql_en = pstJpegeQl->user_ql_en;
    memcpy(h->reconfig.qmem_table, pstJpegeQl->qmem_table, sizeof(pstJpegeQl->qmem_table));
    IJPEGE_RCFG_QL_SET(h->reconfig.idr_reconfig_cnt);
    ijpege_pthread_mutex_unlock(&h->reconfig.mutex_rcfg);
    return 0;
}

int ijpege_reconfig_ql_get(ijpege_t *h,const void *param)
{
    ijpege_ql_param_t *pstJpegeQl = param;
    ijpege_pthread_mutex_lock(&h->reconfig.mutex_rcfg);
    pstJpegeQl->user_ql_en = h->icodec_io.protocol.jpege.user_ql_en;
    memcpy(pstJpegeQl->qmem_table, h->reconfig.qmem_table,sizeof(pstJpegeQl->qmem_table));
    ijpege_pthread_mutex_unlock(&h->reconfig.mutex_rcfg);
    return 0;
}
